package com.mdb.open.trade.service.trade;


/*
* Copyright (C), 2017-2019 澳发科技(MDB)
* FileName: TfTradeFileExtendInfoService.java
* Author:   you.yichao
* Date:     2019-10-11
* History:
* <author>          <time>          <version>          <desc>
* you.yichao         2019-10-11          V1.00             代码生成器初始生成代码
* -----------------------------------------------------------
* 作者姓名           修改时间           版本号            描述
*/


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.database.mybatisplus.SuperService;
import com.mdb.open.trade.common.MdbDataSource;
import com.mdb.open.trade.domain.bo.trade.SaveTradeFileExtendInfoBo;
import com.mdb.open.trade.domain.bo.trade.UpdateTradeFileExtendInfoBo;
import com.mdb.open.trade.domain.po.trade.TradeFileExtendInfo;
import com.mdb.open.trade.mapper.trade.TfTradeFileExtendInfoMapper;
import org.springframework.stereotype.Service;

/**
 * 类描述：
 *  贸易档案额外信息表 服务类
 *
 * @author you.yichao
 * @date 2019-10-11
 */
@Service
@DS(MdbDataSource.TRADE)
public class TfTradeFileExtendInfoService extends SuperService<TfTradeFileExtendInfoMapper, TradeFileExtendInfo> {

    public ResultEx<TradeFileExtendInfo> getInfoByNo(String tradeFileNo) {
        return ResultEx.ok(this.baseMapper.selectOne(new LambdaQueryWrapper<TradeFileExtendInfo>()
                .eq(TradeFileExtendInfo::getTradeFileNo, tradeFileNo)));
    }

    public ResultEx saveExtendInfo(SaveTradeFileExtendInfoBo bo) {

        TradeFileExtendInfo saveExtendInfo = new TradeFileExtendInfo();
        saveExtendInfo.setTradeFileNo(bo.getTradeFileNo());
        saveExtendInfo.setBusinessNo(bo.getBusinessNo());
        saveExtendInfo.setCustomerCode(bo.getCustomerCode());
        saveExtendInfo.setMcustomerCode(bo.getMcustomerCode());
        saveExtendInfo.setCustomerName(bo.getCustomerName());
        saveExtendInfo.setMerchantNo(bo.getMerchantNo());
        saveExtendInfo.setMerchantName(bo.getMerchantName());
        saveExtendInfo.setDepositAmount(bo.getDepositAmount());
        saveExtendInfo.setDepositCcy(bo.getDepositCcy());
        saveExtendInfo.setDepositPercent(bo.getDepositPercent());
        saveExtendInfo.setInsuranceAmount(bo.getInsuranceAmount());
        saveExtendInfo.setInsuranceCcy(bo.getInsuranceCcy());
        saveExtendInfo.setInsurancePercent(bo.getInsurancePercent());
        saveExtendInfo.setSourceType(bo.getSourceType());

        int count = this.baseMapper.insert(saveExtendInfo);
        if (count != 1) {
            return ResultEx.fail();
        }

        return ResultEx.ok();
    }

    public ResultEx updateExtendInfo(UpdateTradeFileExtendInfoBo bo) {

        TradeFileExtendInfo updateExtendInfo = new TradeFileExtendInfo();
        updateExtendInfo.setTradeFileNo(bo.getTradeFileNo());
        updateExtendInfo.setDepositAmount(bo.getDepositAmount());
        updateExtendInfo.setDepositCcy(bo.getDepositCcy());
        updateExtendInfo.setDepositPercent(bo.getDepositPercent());
        updateExtendInfo.setInsuranceAmount(bo.getInsuranceAmount());
        updateExtendInfo.setInsuranceCcy(bo.getInsuranceCcy());
        updateExtendInfo.setInsurancePercent(bo.getInsurancePercent());

        LambdaUpdateWrapper<TradeFileExtendInfo> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(TradeFileExtendInfo::getTradeFileNo, bo.getTradeFileNo());

        int count = this.baseMapper.update(updateExtendInfo, updateWrapper);
        if (count != 1) {
            return ResultEx.fail();
        }
        return ResultEx.ok();

    }

}
